<ui:component xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:m="http://www.ol4jsf.org"
	xmlns:o="http://openfaces.org/"
	xmlns:a4j="http://richfaces.org/a4j">

	<style>
		.noMaskClass .rich-mpnl-mask-div {
			display:none;
		}
		.contentRights {
			width:100%;
			height:155px;
			overflow:auto;
		}
	</style>
	
	<a4j:loadScript src="/viewer/toolbox/js/baseMath.js" />
	<a4j:loadScript src="/viewer/toolbox/js/createSplit.js" />
	

	<h:panelGroup id="drawBoundaryFunctions">
		<script type="text/javascript">
			function drawBoundaryReRender() {
				var wkt = '#{interactiveViewerHelper.borderHelper.borderWKT}';
				if (wkt != null) {
					if (wkt == '') {
						clearMap();
					}
					else {
						var borderFeature = new OpenLayers.Format.WKT().read(wkt);
						clearMap();
						vlayer.addFeatures([borderFeature]);
					}
				}
			}
		</script>
	</h:panelGroup>
	
	<h:form>
		<a4j:jsFunction name="drawBoundary"
			reRender="drawBoundaryFunctions"
			oncomplete="drawBoundaryReRender()">
		</a4j:jsFunction>
	</h:form>
	
	<rich:modalPanel id="splitPanelToolbox" minWidth="520" minHeight="510" resizeable="true" styleClass="noMaskClass" zindex="10000">
		<f:facet name="header">
			<h:outputText value="#{messages['dataentry.split.title']}" rendered="#{interactiveViewerHelper.borderEditMode == 'SPLIT_MERGE' or interactiveViewerHelper.borderEditMode == 'MIXED'}"/>
			<h:outputText value=" / " rendered="#{interactiveViewerHelper.borderEditMode == 'MIXED'}"/>
			<h:outputText value="#{messages['dataentry.create_zone.title']}" rendered="#{interactiveViewerHelper.borderEditMode == 'CREATE' or interactiveViewerHelper.borderEditMode == 'MIXED'}"/>
		</f:facet>
		
		<f:facet name="controls">
			<h:panelGroup>
				<h:graphicImage value="/img/close.png" styleClass="hidelink"
					id="hideSplitPanel" />
				<rich:componentControl for="splitPanelToolbox" attachTo="hideSplitPanel"
					operation="hide" event="onclick" />
			</h:panelGroup>
		</f:facet>

		
		<h:panelGroup id="splitParcelPanel" rendered="#{interactiveViewerHelper.borderEditMode == 'SPLIT_MERGE' or interactiveViewerHelper.borderEditMode == 'MIXED'}">
			<ui:include src="includes/selectedZoneTlb.xhtml" />
		</h:panelGroup>

		<rich:tabPanel switchType="client">
			<rich:tab label="#{messages['txt.border.method1']}">
				<ui:include src="includes/borderMethod1.xhtml" />
			</rich:tab>
			
			<rich:tab label="#{messages['txt.border.method2']}">
				<ui:include src="includes/borderMethod2.xhtml" />
			</rich:tab>
			
			<rich:tab label="#{messages['txt.border.method3']}">
				<ui:include src="includes/borderMethod3.xhtml" />
			</rich:tab>
		</rich:tabPanel>
				
		<br />
		

		<h:form rendered="#{interactiveViewerHelper.borderEditMode != 'NONE'}">
			<div align="center">
				<a4j:commandButton value="Aplicar cambios" action="#{interactiveViewerHelper.borderHelper.doOperation}"
						reRender="#{interactiveViewerHelper.reRenderList}, coords, bearingAndDistanceTable"
						rendered="#{interactiveViewerHelper.borderEditMode == 'SPLIT_MERGE' or interactiveViewerHelper.borderEditMode == 'MIXED'}"
						oncomplete="if (#{facesContext.maximumSeverity==null}) {drawParcelsReRender(); resetInputs();} else #{rich:component('msgPanel')}.show();">
					<f:setPropertyActionListener target="#{interactiveViewerHelper.borderHelper.viewerCallable}" value="#{interactiveViewerHelper.splitCallable}" />
				</a4j:commandButton>
				<a4j:commandButton value="Crear Zona espacial" action="#{interactiveViewerHelper.borderHelper.doOperation}"
						reRender="#{interactiveViewerHelper.reRenderList}, grpDrawCreatedZone, coords, bearingAndDistanceTable"
						rendered="#{interactiveViewerHelper.borderEditMode == 'CREATE' or interactiveViewerHelper.borderEditMode == 'MIXED'}"
						oncomplete="if (#{facesContext.maximumSeverity==null}) {drawCreatedZoneJS(); drawParcelsReRender(); resetInputs();} else #{rich:component('msgPanel')}.show();">
					<f:setPropertyActionListener target="#{interactiveViewerHelper.borderHelper.viewerCallable}" value="#{interactiveViewerHelper.createZoneCallable}" />
				</a4j:commandButton>
			</div>
		</h:form>
	</rich:modalPanel>
	

	<h:form>
		<a4j:jsFunction name="deleteLastBoundaryPoint"
			action="#{interactiveViewerHelper.borderHelper.deleteLastBoundaryPoint}"
			reRender="drawBoundaryFunctions, coords, bearingAndDistanceTable"
			oncomplete="drawBoundaryReRender()">
		</a4j:jsFunction>
		<a4j:jsFunction name="clearBoundary"
			action="#{interactiveViewerHelper.borderHelper.clearBoundary}"
			reRender="coords, bearingAndDistanceTable"
			oncomplete="resetInputs(); clearMap();">
		</a4j:jsFunction>
		<a4j:jsFunction
			name="uploadFileFun"
			action="#{interactiveViewerHelper.borderHelper.uploadNewFile}"
			reRender="frmUploadFile"
			oncomplete="#{rich:component('uploadFileDlg')}.show();">
		</a4j:jsFunction>
	</h:form>
	
	
	<ui:include src="includes/borderUploadFile.xhtml" />
</ui:component>

